package com.jiangjiang.eshop.cart.controller;

import com.jiangjiang.eshop.cart.service.ShoppingCartItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ShoppingCartItemController
 * @Description TODO
 * @Author jhw
 * @Date 2021/7/6 22:47
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/cart/item")
public class ShoppingCartItemController {
    /**
     * 购物车条目管理service组件
     */
    @Autowired
    private ShoppingCartItemService shoppingCartItemService;

    /**
     * 更新购物车条目的购买数量
     *
     * @param id               购物车条目id
     * @param purchaseQuantity 购买数量
     * @return 处理结果
     */
    @GetMapping("/updatePurchaseQuantity")
    public Boolean updatePurchaseQuantity(@RequestParam("id") Long id,
                                          @RequestParam("purchaseQuantity") Long purchaseQuantity) {
        try {
            return shoppingCartItemService.updatePurchaseQuantity(id, purchaseQuantity);
        } catch (Exception e) {
            log.error("error", e);
            return false;
        }
    }


    /**
     * 删除购物车条目
     *
     * @param id 购物车条目id
     * @return 处理结果
     */
    @GetMapping("/removeById")
    public Boolean remove(@RequestParam("id") Long id) {
        try {
            return shoppingCartItemService.removeById(id);
        } catch (Exception e) {
            log.error("error", e);
            return false;
        }
    }

}
